package 查找.树.普通树;

import java.util.List;

/**
 * 普通的数
 * 一个根节点可以有好几个子节点
 */
public class TreeNode {

    // 数据
    public Object data;
    // 父亲
    public TreeNode parentTree;
    // 子树
    public List<TreeNode> childTree;

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public TreeNode getParentTree() {
        return parentTree;
    }

    public void setParentTree(TreeNode parentTree) {
        this.parentTree = parentTree;
    }

    public List<TreeNode> getChildTree() {
        return childTree;
    }

    public void setChildTree(List<TreeNode> childTree) {
        this.childTree = childTree;
    }

    public TreeNode(Object data, TreeNode parentTree) {
        this.data = data;
        this.parentTree = parentTree;
    }

    // 前序遍历（先序遍历）
    public void iterate(TreeNode treeNode) {
        System.out.println("data is : " + treeNode.getData());
        for (TreeNode node:treeNode.getChildTree()) {
            if (node.getChildTree() == null) {
                System.out.println("data is : " + node.getData());
                continue;
            } else {
                iterate(node);
            }
        }
    }
}
